package com.hntest.service.impl;

import com.hntest.dao.BidRequestDao;
import com.hntest.entity.BidRequest;
import com.hntest.entity.Pager;
import com.hntest.service.BidRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("bidRequestService")
public class BidRequestServiceImpl implements BidRequestService {
    @Autowired
    private BidRequestDao bidRequestDao;

    public void setBidRequestDao(BidRequestDao bidRequestDao) {
        this.bidRequestDao = bidRequestDao;
    }

    @Override
    public int getCounts(BidRequest bidRequest) {
        return bidRequestDao.getCounts(bidRequest);
    }

    @Override
    public List<BidRequest> getListByPage(Pager pager, BidRequest bidRequest) {
        //查询总数量
        pager.setTotalCounts(bidRequestDao.getCounts(bidRequest));
        //将值存入map中
        Map<String, Object> map = new HashMap<>();
        map.put("bidRequest",bidRequest);
        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());
        //将map中带回的数据保存到list集合中返回
        List<BidRequest> list = bidRequestDao.getListByPage(map);
        return list;
    }

    @Override
    public List<BidRequest> getListByPage1(Pager pager, BidRequest bidRequest) {
        //查询总数量
        pager.setTotalCounts(bidRequestDao.getCounts(bidRequest));
        //将值存入map中
        Map<String, Object> map = new HashMap<>();
        map.put("bidRequest",bidRequest);
        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());
        //将map中带回的数据保存到list集合中返回
        List<BidRequest> list = bidRequestDao.getListByPage1(map);
        return list;
    }

    @Override
    public List<BidRequest> getListByPage2(Pager pager, BidRequest bidRequest) {
        //查询总数量
        pager.setTotalCounts(bidRequestDao.getCounts(bidRequest));
        //将值存入map中
        Map<String, Object> map = new HashMap<>();
        map.put("bidRequest",bidRequest);
        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());
        //将map中带回的数据保存到list集合中返回
        List<BidRequest> list = bidRequestDao.getListByPage2(map);
        return list;
    }

    @Override
    public BidRequest getBidRequestById(int bid) {
        return bidRequestDao.getBidRequestById(bid);
    }

    @Override
    public int update(BidRequest bidRequest) {
        return bidRequestDao.update(bidRequest);
    }
}
